<%--
  Created by IntelliJ IDEA.
  User: teacher
  Date: 2023/11/2
  Time: 16:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>关键字搜索</title>
    <style>
        li {
            list-style: none;
        }

        #d {
            border: 1px solid #0000ff;
            width: 288px;
            border-top: 0px;
            max-height: 200px;
            overflow: auto;
            padding: 3px 5px;
            display: none;
        }
    </style>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
    <script>
        $(function () {
            $("#spell").keyup(function () {
                $("#d").empty();
                if ($(this).val() == "") {
                    $("#d").hide();
                    return;
                }
                $.ajax({
                    type:"post",
                    url:"${pageContext.request.contextPath}/query",
                    data:{"spell":$(this).val()},
                    dataType:"json",
                    success:function(datas){
                        if(datas.length == 0){
                            $("#d").hide();
                            return;
                        }
                        $("#d").show();
                        $(datas).each(function(){
                            $("#d").append("<li>"+this.message+"</li>");
                        });
                    }
                })
            });
        });
    </script>
</head>
<body>
<input id="spell" type="text" style="width: 300px;">
<div id="d">
</div>
</body>
</html>
